home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / vesa122 / vesahdr.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1994-12-04  |  38.8 KB  |  601 lines

  1. Unit VESA;
  2. {$A+}           {Enable Word Alignment}
  3. {$G+}           {Enable 80286/80287 Instructions}
  4. {$F+}           {FAR CALLS are ON}
  5. {$S-}           {No Stack Checking}
  6. {$R-}           {No Range Checking}
  7. {$Q-}           {No Overflow Checking}
  8. {$Y-}           {No Symbol Generation}
  9.  
  10.  
  11. (**************VESA Unit Written by Romesh Prakashpalan, 1994**************)
  12. (********General Purpose Library for HIGH PERFORMANCE VESA graphics********)
  13. (***********As of version 1.22 only 640x480x256 FULLY supported************)
  14. (*                                                                        *)
  15. (*========================================================================*)
  16. (*                           Introduction                                 *)
  17. (*========================================================================*)
  18. (*       This Unit is a clean break from my GraphHi2 unit, which was VERY *)
  19. (*       messy, and failed at times. The parts that failed were due to the*)
  20. (*       fact that my routines did not adjust for bank granularities that *)
  21. (*       were less than 64K long, plus the bank switching functions for   *)
  22. (*       VESA did not work reliably at times. All of these problems plus  *)
  23. (*       more are fixed in this version, plus support for cards other than*)
  24. (*       VESA were dropped (all of these cards cards can be tricked into  *)
  25. (*       thinking they are a VESA card with a very small TSR). However,   *)
  26. (*       the biggest difference is in that now many KEY routines are      *)
  27. (*       written in ASSEMBLY. This allows for blazing speed (relative) to *)
  28. (*       TP instructions. If you have the source code (only my friends    *)
  29. (*       do), then you will see that there is an enourmous amount of      *)
  30. (*       assembly, where the previous versions didn't have much.          *)
  31. (*                                                                        *)
  32. (* Some brand new procedures (not in GraphHi2) are listed below:          *)
  33. (*========================================================================*)
  34. (*    Procedure Circle (CenterX, CenterY, Radius: Integer; Color: Byte);  *)
  35. (*    Procedure WaitRetrace;                                              *)
  36. (*    Procedure FadeCurs;                                                 *)
  37. (*    Procedure SetDisplay (X, Y: Word);                                  *)
  38. (*========================================================================*)
  39. (* Circle draws a circle centered at CenterX, CenterY, with a Radius of   *)
  40. (* Radius, and a Color of Color. WaitRetrace waits for the vertical       *)
  41. (* retrace of the (S)VGA board to complete, thereby allowing your code to *)
  42. (* set the palette flicker free. FadeCurs fades out a text screen (First  *)
  43. (* time I saw this, I said WOW!, this looks professional (compared to     *)
  44. (* blanking out the text screen immediately). SetDisplay will pan         *)
  45. (* to location X, Y (in any 256 color modes) utilizing hardware panning,  *)
  46. (* it is incredibly smooth, and if one can properly utilize it, it        *)
  47. (* can create breathtaking results (horizontal panning especially)        *)
  48. (*                                                                        *)
  49. (*+----------------------------------------------------------------------+*)
  50. (*|NOTE: When drawing circles, make sure that they do not go off of the  |*)
  51. (*|      screen!, my code does not compensate for such an occurence, so  |*)
  52. (*|      beware!!                                                        |*)
  53. (*+----------------------------------------------------------------------+*)
  54. (* For those of you who have been programming with the Borland BGI        *)
  55. (* routines, in order to convert programs that use the Graph unit, change *)
  56. (* the Uses Graph --> Uses VESA, and change all of the routines in your   *)
  57. (* old code to their equivalents in the VESA library, you should notice a *)
  58. (* tremendous speed increase (unless you are using 256 color fills, which *)
  59. (* take a LOT longer than their 16-color counterparts).                   *)
  60. (* What I personally didn't (and still don't) like about Borland's BGI    *)
  61. (* routines, is that they had a LOT of overhead, and they called the BIOS *)
  62. (* for a few routines. They were also very unoptimized (most people could *)
  63. (* probably write faster code in their sleep...), 256 color support was   *)
  64. (* virtually nil, and VESA modes were a laugh (16-colors at best!). It    *)
  65. (* reportedly takes a much LONGER time to create a BGI file for a certain *)
  66. (* graphics adapter than it would be to program it into a .TPU or .TPP!   *)
  67. (*                                                                        *)
  68. (* Well, that's about it, enjoy...                                        *)
  69. (*                             Romesh Prakashpalan, 1994                  *)
  70. (*                                                                        *)
  71. (* References:                                                            *)
  72. (*   Super VGA Graphics Programming Secrets (By Steve Rimmer):            *)
  73. (*     This is a decent book on how to program SVGA cards in their native *)
  74. (*     and VESA modes. However, he programs in a mixture of C and external*)
  75. (*     assembly, and he doesn't expain too much of what he is doing. Plus,*)
  76. (*     his code is pretty much unoptimized (not too bad though).          *)
  77. (*   VESASP12.TXT:                                                        *)
  78. (*     PCGPE article on programming in VESA modes (I personally didn't use*)
  79. (*     it, but it has the COMPLETE VESA standard in it).                  *)
  80. (*========================================================================*)
  81. (*   Revision History:                                                    *)
  82. (*     Version 0.5α: GraphHi2 (VERY BUGGY and MESSY). Only supported cards*)
  83. (*                   with a 64K bank granularity (BIG mistake!), and also *)
  84. (*                   the bank switching function was faulty! (stoopid     *)
  85. (*                   mistake), it is a piece of SH*T! (04/94). Plus, there*)
  86. (*                   is very little assembly code (only where I NEED it), *)
  87. (*                   and I hope to have this corrected in the next version*)
  88. (*     Version 0.9ß: First Release (fixed above bugs), scrapped v0.1α, and*)
  89. (*                   started from scratch (v0.1α had NO comments).        *)
  90. (*                   Unfortunately, I am using Turbo Pascal's MOVE and    *)
  91. (*                   FILLCHAR instructions instead of MOVSB and STOSB.    *)
  92. (*                   This will definitely be fixed in the next release!   *)
  93. (*                   *Note*: I was using an i386DX-25 to test the routines*)
  94. (*                   in Version 0.1α, so I was able to tell the difference*)
  95. (*                   between a QUICK algorithm and a sloooow one very     *)
  96. (*                   easily, but now I upgraded to a PENTIUM, and really, *)
  97. (*                   the only way I can tell if my routines are any faster*)
  98. (*                   is by going over THEORY, not by practice (all the    *)
  99. (*                   damn routines seem to execute at the same speed!)    *)
  100. (*     Version 1.0ß: Added Assembly portions to PutPixel routine, and as  *)
  101. (*                   promised, added REAL assembly language routines to   *)
  102. (*                   fix lack of MOVSB and STOSB (got rid of a lot of     *)
  103. (*                   MOVE and FILLCHAR instructions). Also added GetImage *)
  104. (*                   and PutImage, but these still use the TP MOVE command*)
  105. (*                   More and Better palette support routines were added  *)
  106. (*                   as well!                                             *)
  107. (*     Version 1.1a: Added support for Panning, Vertical Retrace, and now *)
  108. (*                   FillRect and ClearScreen moves WORDS instead of BYTES*)
  109. (*     Version 1.2 : Dropped support for 16-bit CPUs (sorry :-( ), and    *)
  110. (*                   PutPixel now supports the 32-bit math for 80386+ CPUs*)
  111. (*                   so it now can scream with the best of 'em, and I also*)
  112. (*                   got SetBank to call the WINFUNPTR instead of doing an*)
  113. (*                   INT 10h (Now, it is much faster)                     *)
  114. (*                   (At this point, I'd be hard pressed to get much more *)
  115. (*                    SIGNIFICANT speed out of this product, so from now  *)
  116. (*                    on, I shall concentrate on adding more features...) *)
  117. (*                   As it stands, it is much faster than the code in     *)
  118. (*                   Steve Rimmer's book: Super VGA programming secrets,  *)
  119. (*                   (But, then again he used a mixture of C and EXTERNAL *)
  120. (*                   16-bit assembly (yuck!)). In fact, much of the code  *)
  121. (*                   was derived from his book, then I put in a few       *)
  122. (*                   optimizations and special features which weren't     *)
  123. (*                   present in his.                                      *)
  124. (*     Version 1.21: A minor upgrade from Version 1.2, a few relatively   *)
  125. (*                   minor optimizations were made, and I added support   *)
  126. (*                   for 2 assembly language procedures which should      *)
  127. (*                   replace the need for using TP's MOVE and FILLCHAR    *)
  128. (*                   instructions (for writing to the screen at least).   *)
  129. (*                   These procedures, while not as fast assembly dropped *)
  130. (*                   right in the middle of your code, is MUCH faster than*)
  131. (*                   the TP Move and FillChar instructions, since they    *)
  132. (*                   move WORDS, and not BYTES. Also, I have created a    *)
  133. (*                   SEPERATE Unit that allows one to view PCX and iRP.   *)
  134. (*                   For those of you who are saying iRP?, what file      *)
  135. (*                   format is that?, well it is a file format created by *)
  136. (*                   ME. Since PCX files take too long to unpack off of   *)
  137. (*                   disk, and have negative compression when dealing with*)
  138. (*                   scanned images, I just created the iRP file format to*)
  139. (*                   get around that (I even created an utility to convert*)
  140. (*                   from PCX->iRP). As of yet, it doesn't support any    *)
  141. (*                   kind of compression algorithm, but there is a lot of *)
  142. (*                   flexibility in the format if I wanted to do so.      *)
  143. (*                   Oh, by the way, GetPixel has FINALLY been rewritten  *)
  144. (*                   in assembly language, so it and PutPixel are finally *)
  145. (*                   at an equal footing. Plus, I got ClearScreen to xfer *)
  146. (*                   double words instead of words (now, it really cooks, *)
  147. (*                   and starts to move my product into the 32-bit        *)
  148. (*                   direction). The next procedure that needs to be      *)
  149. (*                   implemented in 32-bit assembly (IMHO) is FillRect.   *)
  150. (*                   If I get FillRect to write Double Words instead of   *)
  151. (*                   Words, the product will be much faster. If I get this*)
  152. (*                   done, there isn't any other place (that I can see)   *)
  153. (*                   that can benefit from 32-bit assembly (except for    *)
  154. (*                   GetImage and PutImage).                              *)
  155. (*                   I have charted the speed increase of my code (using  *)
  156. (*                   Turbo Profiler, and my code is now approx 45% faster *)
  157. (*                   than version 0.5α!(and 25% faster than Steve Rimmers)*)
  158. (*     Version 1.22: Now, PutImage has been rewritten in assembly (key    *)
  159. (*                   parts only), and GetImage has also been rewritten in *)
  160. (*                   assembly (again, only the key parts).                *)
  161. (*  Future Releases: Now, finally ALL of my routines have assembly where  *)
  162. (*                   they absolutely needed them the most. GetImage and   *)
  163. (*                   PutImage have been rewritten in Version 1.22, so I   *)
  164. (*                   believe that only a few optimizations shall be needed*)
  165. (*                   from now on. Come on, you have to admit that for VESA*)
  166. (*                   modes (hi-res), my routines are pretty fast! (esp.   *)
  167. (*                   since I don't have MULTIPLE PAGES to work with, and  *)
  168. (*                   that I have to switch banks in order to address      *)
  169. (*                   pixels outside of a bank!                            *)
  170. (*                   For many applications however, hi-res VESA Modes are *)
  171. (*                   VERY nice to have (pretty much picture resolutions), *)
  172. (*                   so if you can get away with creating games in such an*)
  173. (*                   environment, do it, (games like Gateway, and The 7th *)
  174. (*                   guest pop up in my mind)                             *)
  175. (*============================Stuff to think about========================*)
  176. (*------------------------------------------------------------------------*)
  177. (*                        One might think that using a 32-bit environment *)
  178. (*                  to access the video card (like 32-bit extenders) might*)
  179. (*                  speed up the code a bit (after all, a 4GB flat address*)
  180. (*                  space is pretty nice), however we can still only SEE  *)
  181. (*                  64K on the card, because the CARD was designed that   *)
  182. (*                  way! So, while other portions of your code might run  *)
  183. (*                  faster (XMS memory access), don't count on the video  *)
  184. (*                  card go any faster, in fact it will go a lot SLOWER,  *)
  185. (*                  because you have to switch from 32-bit mode to 16-bit *)
  186. (*                  mode everytime you want to access the video RAM!      *)
  187. (*------------------------------------------------------------------------*)
  188. (*                  God is REAL unless defined as an INTEGER...           *)
  189. (*                    -The above statement doesn't work in C/C++ (we all  *)
  190. (*                     know that people who program in C are Godless      *)
  191. (*                     heathens! ;-) ).                                   *)
  192. (*------------------------------------------------------------------------*)
  193. (*                  C is more decipherable disassembled than in its source*)
  194. (*                  code form...                                          *)
  195. (*                    -Oh, how true it is!                                *)
  196. (*------------------------------------------------------------------------*)
  197. (*                  Some newbies to computer graphics, see VESA modes as a*)
  198. (*                  better environment for game programming. Sadly, this  *)
  199. (*                  is not always the case. If you are going for that     *)
  200. (*                  Mortal Kombat/Street Fighter/Action Arcade Game look  *)
  201. (*                  and feel, then hi-res VESA modes are not for you, and *)
  202. (*                  you should be looking at Mode-X graphics programming  *)
  203. (*                  instead (320x200x256). Hi-Res VESA modes do not have  *)
  204. (*                  some of the "neat" features that the lower-res modes  *)
  205. (*                  do, such as multiple pages (with 1 visible page), for *)
  206. (*                  fast graphics "flipping", and the ability to write off*)
  207. (*                  of the screen (for scrolling). Instead, the hi-res    *)
  208. (*                  VESA programmer is better off doing programming for   *)
  209. (*                  games more like those found in the Ultima series (up  *)
  210. (*                  to VII part 2), and Sierra type games. Other types of *)
  211. (*                  games require much more speed than VESA modes provide *)
  212. (*                  However, my routines are MUCH faster than ANY code    *)
  213. (*                  written for the BGI routines, so if you had a program *)
  214. (*                  running just fine under them, you will notice an      *)
  215. (*                  ENORMOUS SPEED INCREASE under mine (in some cases, as *)
  216. (*                  high as 1000%! (1 thousand, not a typo)).             *)
  217. (*========================================================================*)
  218. (*                  If you have any suggestions, for future releases,     *)
  219. (*                  e-mail me at hacscb93@hp.csun.edu (until 01/15/95)    *)
  220. (*                  Registration fee is $20 for non-commercial version,   *)
  221. (*                  $50 for the commercial version. *Note: Version 1.22 is*)
  222. (*                  the first to be sent to the public, so whoever reports*)
  223. (*                  a new bug in the code will get their registration free*)
  224. (*                  of charge! Contact me first before paying the         *)
  225. (*                  registration fee (I might have changed my Internet    *)
  226. (*                  address!). Also note that you have to contact me first*)
  227. (*                  telling me what type of bug was detected (I might have*)
  228. (*                  already received a bug report of the same type!)      *)
  229. (*========================================================================*)
  230.  
  231. (* (By Microsoft standards, perhaps I shall rename this Unit to VESA94 ;-)*)
  232. Unit VESA;
  233. {$A+}           {Enable Word Alignment}
  234. {$G+}           {Enable 80286/80287 Instructions}
  235. {$F+}           {FAR CALLS are ON}
  236. {$S-}           {No Stack Checking}
  237. {$R-}           {No Range Checking}
  238. {$Q-}           {No Overflow Checking}
  239. {$Y-}           {No Symbol Generation}
  240.  
  241.  
  242. (**************VESA Unit Written by Romesh Prakashpalan, 1994**************)
  243. (********General Purpose Library for HIGH PERFORMANCE VESA graphics********)
  244. (***********As of version 1.22 only 640x480x256 FULLY supported************)
  245. (*                                                                        *)
  246. (*========================================================================*)
  247. (*                           Introduction                                 *)
  248. (*========================================================================*)
  249. (*       This Unit is a clean break from my GraphHi2 unit, which was VERY *)
  250. (*       messy, and failed at times. The parts that failed were due to the*)
  251. (*       fact that my routines did not adjust for bank granularities that *)
  252. (*       were less than 64K long, plus the bank switching functions for   *)
  253. (*       VESA did not work reliably at times. All of these problems plus  *)
  254. (*       more are fixed in this version, plus support for cards other than*)
  255. (*       VESA were dropped (all of these cards cards can be tricked into  *)
  256. (*       thinking they are a VESA card with a very small TSR). However,   *)
  257. (*       the biggest difference is in that now many KEY routines are      *)
  258. (*       written in ASSEMBLY. This allows for blazing speed (relative) to *)
  259. (*       TP instructions. If you have the source code (only my friends    *)
  260. (*       do), then you will see that there is an enourmous amount of      *)
  261. (*       assembly, where the previous versions didn't have much.          *)
  262. (*                                                                        *)
  263. (* Some brand new procedures (not in GraphHi2) are listed below:          *)
  264. (*========================================================================*)
  265. (*    Procedure Circle (CenterX, CenterY, Radius: Integer; Color: Byte);  *)
  266. (*    Procedure WaitRetrace;                                              *)
  267. (*    Procedure FadeCurs;                                                 *)
  268. (*    Procedure SetDisplay (X, Y: Word);                                  *)
  269. (*========================================================================*)
  270. (* Circle draws a circle centered at CenterX, CenterY, with a Radius of   *)
  271. (* Radius, and a Color of Color. WaitRetrace waits for the vertical       *)
  272. (* retrace of the (S)VGA board to complete, thereby allowing your code to *)
  273. (* set the palette flicker free. FadeCurs fades out a text screen (First  *)
  274. (* time I saw this, I said WOW!, this looks professional (compared to     *)
  275. (* blanking out the text screen immediately). SetDisplay will pan         *)
  276. (* to location X, Y (in any 256 color modes) utilizing hardware panning,  *)
  277. (* it is incredibly smooth, and if one can properly utilize it, it        *)
  278. (* can create breathtaking results (horizontal panning especially)        *)
  279. (*                                                                        *)
  280. (*+----------------------------------------------------------------------+*)
  281. (*|NOTE: When drawing circles, make sure that they do not go off of the  |*)
  282. (*|      screen!, my code does not compensate for such an occurence, so  |*)
  283. (*|      beware!!                                                        |*)
  284. (*+----------------------------------------------------------------------+*)
  285. (* For those of you who have been programming with the Borland BGI        *)
  286. (* routines, in order to convert programs that use the Graph unit, change *)
  287. (* the Uses Graph --> Uses VESA, and change all of the routines in your   *)
  288. (* old code to their equivalents in the VESA library, you should notice a *)
  289. (* tremendous speed increase (unless you are using 256 color fills, which *)
  290. (* take a LOT longer than their 16-color counterparts).                   *)
  291. (* What I personally didn't (and still don't) like about Borland's BGI    *)
  292. (* routines, is that they had a LOT of overhead, and they called the BIOS *)
  293. (* for a few routines. They were also very unoptimized (most people could *)
  294. (* probably write faster code in their sleep...), 256 color support was   *)
  295. (* virtually nil, and VESA modes were a laugh (16-colors at best!). It    *)
  296. (* reportedly takes a much LONGER time to create a BGI file for a certain *)
  297. (* graphics adapter than it would be to program it into a .TPU or .TPP!   *)
  298. (*                                                                        *)
  299. (* Well, that's about it, enjoy...                                        *)
  300. (*                             Romesh Prakashpalan, 1994                  *)
  301. (*                                                                        *)
  302. (* References:                                                            *)
  303. (*   Super VGA Graphics Programming Secrets (By Steve Rimmer):            *)
  304. (*     This is a decent book on how to program SVGA cards in their native *)
  305. (*     and VESA modes. However, he programs in a mixture of C and external*)
  306. (*     assembly, and he doesn't expain too much of what he is doing. Plus,*)
  307. (*     his code is pretty much unoptimized (not too bad though).          *)
  308. (*   VESASP12.TXT:                                                        *)
  309. (*     PCGPE article on programming in VESA modes (I personally didn't use*)
  310. (*     it, but it has the COMPLETE VESA standard in it).                  *)
  311. (*========================================================================*)
  312. (*   Revision History:                                                    *)
  313. (*     Version 0.5α: GraphHi2 (VERY BUGGY and MESSY). Only supported cards*)
  314. (*                   with a 64K bank granularity (BIG mistake!), and also *)
  315. (*                   the bank switching function was faulty! (stoopid     *)
  316. (*                   mistake), it is a piece of SH*T! (04/94). Plus, there*)
  317. (*                   is very little assembly code (only where I NEED it), *)
  318. (*                   and I hope to have this corrected in the next version*)
  319. (*     Version 0.9ß: First Release (fixed above bugs), scrapped v0.1α, and*)
  320. (*                   started from scratch (v0.1α had NO comments).        *)
  321. (*                   Unfortunately, I am using Turbo Pascal's MOVE and    *)
  322. (*                   FILLCHAR instructions instead of MOVSB and STOSB.    *)
  323. (*                   This will definitely be fixed in the next release!   *)
  324. (*                   *Note*: I was using an i386DX-25 to test the routines*)
  325. (*                   in Version 0.1α, so I was able to tell the difference*)
  326. (*                   between a QUICK algorithm and a sloooow one very     *)
  327. (*                   easily, but now I upgraded to a PENTIUM, and really, *)
  328. (*                   the only way I can tell if my routines are any faster*)
  329. (*                   is by going over THEORY, not by practice (all the    *)
  330. (*                   damn routines seem to execute at the same speed!)    *)
  331. (*     Version 1.0ß: Added Assembly portions to PutPixel routine, and as  *)
  332. (*                   promised, added REAL assembly language routines to   *)
  333. (*                   fix lack of MOVSB and STOSB (got rid of a lot of     *)
  334. (*                   MOVE and FILLCHAR instructions). Also added GetImage *)
  335. (*                   and PutImage, but these still use the TP MOVE command*)
  336. (*                   More and Better palette support routines were added  *)
  337. (*                   as well!                                             *)
  338. (*     Version 1.1a: Added support for Panning, Vertical Retrace, and now *)
  339. (*                   FillRect and ClearScreen moves WORDS instead of BYTES*)
  340. (*     Version 1.2 : Dropped support for 16-bit CPUs (sorry :-( ), and    *)
  341. (*                   PutPixel now supports the 32-bit math for 80386+ CPUs*)
  342. (*                   so it now can scream with the best of 'em, and I also*)
  343. (*                   got SetBank to call the WINFUNPTR instead of doing an*)
  344. (*                   INT 10h (Now, it is much faster)                     *)
  345. (*                   (At this point, I'd be hard pressed to get much more *)
  346. (*                    SIGNIFICANT speed out of this product, so from now  *)
  347. (*                    on, I shall concentrate on adding more features...) *)
  348. (*                   As it stands, it is much faster than the code in     *)
  349. (*                   Steve Rimmer's book: Super VGA programming secrets,  *)
  350. (*                   (But, then again he used a mixture of C and EXTERNAL *)
  351. (*                   16-bit assembly (yuck!)). In fact, much of the code  *)
  352. (*                   was derived from his book, then I put in a few       *)
  353. (*                   optimizations and special features which weren't     *)
  354. (*                   present in his.                                      *)
  355. (*     Version 1.21: A minor upgrade from Version 1.2, a few relatively   *)
  356. (*                   minor optimizations were made, and I added support   *)
  357. (*                   for 2 assembly language procedures which should      *)
  358. (*                   replace the need for using TP's MOVE and FILLCHAR    *)
  359. (*                   instructions (for writing to the screen at least).   *)
  360. (*                   These procedures, while not as fast assembly dropped *)
  361. (*                   right in the middle of your code, is MUCH faster than*)
  362. (*                   the TP Move and FillChar instructions, since they    *)
  363. (*                   move WORDS, and not BYTES. Also, I have created a    *)
  364. (*                   SEPERATE Unit that allows one to view PCX and iRP.   *)
  365. (*                   For those of you who are saying iRP?, what file      *)
  366. (*                   format is that?, well it is a file format created by *)
  367. (*                   ME. Since PCX files take too long to unpack off of   *)
  368. (*                   disk, and have negative compression when dealing with*)
  369. (*                   scanned images, I just created the iRP file format to*)
  370. (*                   get around that (I even created an utility to convert*)
  371. (*                   from PCX->iRP). As of yet, it doesn't support any    *)
  372. (*                   kind of compression algorithm, but there is a lot of *)
  373. (*                   flexibility in the format if I wanted to do so.      *)
  374. (*                   Oh, by the way, GetPixel has FINALLY been rewritten  *)
  375. (*                   in assembly language, so it and PutPixel are finally *)
  376. (*                   at an equal footing. Plus, I got ClearScreen to xfer *)
  377. (*                   double words instead of words (now, it really cooks, *)
  378. (*                   and starts to move my product into the 32-bit        *)
  379. (*                   direction). The next procedure that needs to be      *)
  380. (*                   implemented in 32-bit assembly (IMHO) is FillRect.   *)
  381. (*                   If I get FillRect to write Double Words instead of   *)
  382. (*                   Words, the product will be much faster. If I get this*)
  383. (*                   done, there isn't any other place (that I can see)   *)
  384. (*                   that can benefit from 32-bit assembly (except for    *)
  385. (*                   GetImage and PutImage).                              *)
  386. (*                   I have charted the speed increase of my code (using  *)
  387. (*                   Turbo Profiler, and my code is now approx 45% faster *)
  388. (*                   than version 0.5α!(and 25% faster than Steve Rimmers)*)
  389. (*     Version 1.22: Now, PutImage has been rewritten in assembly (key    *)
  390. (*                   parts only), and GetImage has also been rewritten in *)
  391. (*                   assembly (again, only the key parts).                *)
  392. (*  Future Releases: Now, finally ALL of my routines have assembly where  *)
  393. (*                   they absolutely needed them the most. GetImage and   *)
  394. (*                   PutImage have been rewritten in Version 1.22, so I   *)
  395. (*                   believe that only a few optimizations shall be needed*)
  396. (*                   from now on. Come on, you have to admit that for VESA*)
  397. (*                   modes (hi-res), my routines are pretty fast! (esp.   *)
  398. (*                   since I don't have MULTIPLE PAGES to work with, and  *)
  399. (*                   that I have to switch banks in order to address      *)
  400. (*                   pixels outside of a bank!                            *)
  401. (*                   For many applications however, hi-res VESA Modes are *)
  402. (*                   VERY nice to have (pretty much picture resolutions), *)
  403. (*                   so if you can get away with creating games in such an*)
  404. (*                   environment, do it, (games like Gateway, and The 7th *)
  405. (*                   guest pop up in my mind)                             *)
  406. (*============================Stuff to think about========================*)
  407. (*------------------------------------------------------------------------*)
  408. (*                        One might think that using a 32-bit environment *)
  409. (*                  to access the video card (like 32-bit extenders) might*)
  410. (*                  speed up the code a bit (after all, a 4GB flat address*)
  411. (*                  space is pretty nice), however we can still only SEE  *)
  412. (*                  64K on the card, because the CARD was designed that   *)
  413. (*                  way! So, while other portions of your code might run  *)
  414. (*                  faster (XMS memory access), don't count on the video  *)
  415. (*                  card go any faster, in fact it will go a lot SLOWER,  *)
  416. (*                  because you have to switch from 32-bit mode to 16-bit *)
  417. (*                  mode everytime you want to access the video RAM!      *)
  418. (*------------------------------------------------------------------------*)
  419. (*                  God is REAL unless defined as an INTEGER...           *)
  420. (*                    -The above statement doesn't work in C/C++ (we all  *)
  421. (*                     know that people who program in C are Godless      *)
  422. (*                     heathens! ;-) ).                                   *)
  423. (*------------------------------------------------------------------------*)
  424. (*                  C is more decipherable disassembled than in its source*)
  425. (*                  code form...                                          *)
  426. (*                    -Oh, how true it is!                                *)
  427. (*------------------------------------------------------------------------*)
  428. (*                  Some newbies to computer graphics, see VESA modes as a*)
  429. (*                  better environment for game programming. Sadly, this  *)
  430. (*                  is not always the case. If you are going for that     *)
  431. (*                  Mortal Kombat/Street Fighter/Action Arcade Game look  *)
  432. (*                  and feel, then hi-res VESA modes are not for you, and *)
  433. (*                  you should be looking at Mode-X graphics programming  *)
  434. (*                  instead (320x200x256). Hi-Res VESA modes do not have  *)
  435. (*                  some of the "neat" features that the lower-res modes  *)
  436. (*                  do, such as multiple pages (with 1 visible page), for *)
  437. (*                  fast graphics "flipping", and the ability to write off*)
  438. (*                  of the screen (for scrolling). Instead, the hi-res    *)
  439. (*                  VESA programmer is better off doing programming for   *)
  440. (*                  games more like those found in the Ultima series (up  *)
  441. (*                  to VII part 2), and Sierra type games. Other types of *)
  442. (*                  games require much more speed than VESA modes provide *)
  443. (*                  However, my routines are MUCH faster than ANY code    *)
  444. (*                  written for the BGI routines, so if you had a program *)
  445. (*                  running just fine under them, you will notice an      *)
  446. (*                  ENORMOUS SPEED INCREASE under mine (in some cases, as *)
  447. (*                  high as 1000%! (1 thousand, not a typo)).             *)
  448. (*========================================================================*)
  449. (*                  If you have any suggestions, for future releases,     *)
  450. (*                  e-mail me at hacscb93@hp.csun.edu (until 01/15/95)    *)
  451. (*                  Registration fee is $20 for non-commercial version,   *)
  452. (*                  $50 for the commercial version. *Note: Version 1.22 is*)
  453. (*                  the first to be sent to the public, so whoever reports*)
  454. (*                  a new bug in the code will get their registration free*)
  455. (*                  of charge! Contact me first before paying the         *)
  456. (*                  registration fee (I might have changed my Internet    *)
  457. (*                  address!). Also note that you have to contact me first*)
  458. (*                  telling me what type of bug was detected (I might have*)
  459. (*                  already received a bug report of the same type!).     *)
  460. (*                  Note: Information IS FREE! Just not the whole         *)
  461. (*                  source code (so contact me if you need any details on *)
  462. (*                  VESA programming!)                                    *)
  463. (*========================================================================*)
  464.  
  465. (* (By Microsoft standards, perhaps I shall rename this Unit to VESA94 ;-)*)
  466.  
  467. interface
  468. const
  469.   MaskTable: Array [1..8] of Byte = (128, 64, 32, 16, 8, 4, 2, 1);
  470.  (* The above mask is used for interfacing to the char set in the VGA BIOS *)
  471. type
  472.   VESAInfoPtr = ^VesaInfo;
  473.   VESAInfo =  Record
  474.                 ModeAttributes: Word;
  475.                 WindowAttr_A: Byte;
  476.                 WindowAttr_B: Byte;
  477.                 Granularity: Word;
  478.                 WindowSize: Word;
  479.                 WindowSegment_A: Word;
  480.                 WindowSegment_B: Word;
  481.                 WindowPtr: Procedure;
  482.                 BytesPerLine: Word;
  483.                 XRes: Word;
  484.                 YRes: Word;
  485.                 XCharSize: Byte;
  486.                 YCharSize: Byte;
  487.                 NumberofPlanes: Byte;
  488.                 Bitsperpixel: Byte;
  489.                 Banks: Byte;
  490.                 MemoryModel: Byte;
  491.                 BankSize: Byte;
  492.                 ImagePages: Byte;
  493.                 Reserved1: Byte;
  494.                 RedMask: Byte;
  495.                 RedField: Byte;
  496.                 GreenMask: Byte;
  497.                 GreenField: Byte;
  498.                 BlueMask: Byte;
  499.                 BlueField: Byte;
  500.                 ResMask: Byte;
  501.                 ResField: Byte;
  502.                 DirectColor: Byte;
  503.                 Reserved: Array [1..216] of Byte;
  504.               end;
  505.  
  506.   VESABlock = Record
  507.                 VesaSig: Array [1..4] of Char;
  508.                 Version: Word;
  509.                 OemString: PChar;
  510.                 Capabilities: Array [1..4] of Char;
  511.                 VideoMode: ^Word;
  512.                 Memory: Word;
  513.                 Reserved: Array [1..242] of Char;
  514.               end;
  515.  
  516.  ColorType = Record
  517.                 R, G, B : Byte;
  518.              end;
  519.  
  520.  PaletteType = Array[0..255] of ColorType;
  521.  
  522.  BytePtr     = ^Byte;
  523.  
  524.  ImageType   = Record
  525.                  Width: Word;
  526.                  Depth: Word;
  527.                  Buffer: BytePtr;
  528.                end;
  529.  
  530. var
  531.   TempVI: VesaInfo;
  532.   VB: VesaBlock;
  533.   (* Assumes Screen is 480 pixels deep...                       *)
  534.   ScreenTable: Array [0..479] of Record
  535.                                    Offset: Word;
  536.                                    PageNumber: Byte;
  537.                                    Flag: Byte;
  538.                                  end;
  539.  
  540. (* Variables used primarily for ASM procedures                  *)
  541.   WINSIZE: Word;
  542.   WINGRAN: Word;
  543.   BANKSHIFT: WORD;
  544.   BYTESPERLINE: WORD;
  545.   BANKSIZE: WORD;
  546.   XRES, YRES: WORD;
  547.   WINFUNPTR: PROCEDURE;
  548.   FONTSEG: WORD;
  549.   FONTOFS: WORD;
  550.   PALETTE: PALETTETYPE;
  551.   const
  552.     CODEPAGE: WORD = 0;
  553.  
  554.  
  555. (* VESA Mode functions (and system calls)                               *)
  556. Procedure SetText;
  557. Procedure ChangeMode (Mode: Word);
  558. Procedure WaitRetrace;
  559. Procedure SetBank (BANKNUMBER: WORD);
  560. Procedure SetDisplay (X, Y: Integer);
  561.  
  562. (* Pixel related functions:                                             *)
  563. Procedure Putpixel (X,Y : Integer; Color : Byte);
  564. Function  Getpixel (X,Y : Integer): Byte;
  565.  
  566. (* Line Drawing, Circle and Box functions:                              *)
  567. Procedure Line (Left, Top, Right, Bottom: Integer; Color: Byte);
  568. Procedure Circle (CenterX, CenterY, Radius: Integer; Color: Byte);
  569. Procedure FillRect (X1, Y1, X2, Y2: Integer; Color: Byte);
  570. Procedure FrameRect (X1, Y1, X2, Y2: Integer; Color: Byte);
  571.  
  572. (* Palette related procedures:                                          *)
  573. Procedure SetPalette(var Palette : PaletteType);
  574. Procedure GetPalEntry (Color : Byte; var R, G, B : Byte);
  575. Procedure SetPalEntry (Color, R, G, B : Byte);
  576. Procedure FadeDown;
  577. Procedure Fadeup (Pall: PaletteType);
  578. Procedure BlackOut;
  579. Procedure LoadDefaultPalette;
  580. Procedure LoadPalette1;
  581. Procedure LoadPalette2;
  582. Procedure FadeCurs;
  583.  
  584. (* Graphics Text functions:                                             *)
  585. Procedure PutChar (X, Y: Integer; Ch: Char; Color: Byte);
  586. Procedure WriteString (X, Y: Integer; S: String; Color: Byte);
  587.  
  588. (* Image Buffer techniques:                                             *)
  589. Function  ImageSize (X1, Y1, X2, Y2: Integer): LongInt;
  590. Procedure GetImage (var Image: ImageType; X1, Y1, X2, Y2: Integer);
  591. Procedure PutImage (Image: ImageType; X1, Y1: Integer);
  592.  
  593. (* Image filling techniques:                                            *)
  594. Procedure MoveVideoFast (var Buffer; VOffset, Length: Word);
  595. Procedure FillVideoFast (VOffset, Length: Word; Value: Byte);
  596.  
  597. (* Screen Clearing functions:                                           *)
  598. Procedure ClearScreen (Color: Byte);
  599.  
  600. implementation
  601.